#pragma once
#include "ReactorImplementation.h"
#include "Handler.h"
#include "DemuxTable.h"
#include "QueueManager.h"
#include "QueueElement.h"
#include "SyncEventDemultiplexer.h"

#define MAX_NO_OF_HANDLES 10

class ServerReactor :public ReactorImplementation<SOCKET>
{
public:
	ServerReactor(QueueManager<QueueElement>*);
	~ServerReactor(void);
	void register_handler(IEventHandler<SOCKET> *eventHandler, Event_Type eventType);
	void register_handler(Handler<SOCKET> h, IEventHandler<SOCKET> *eventHandler, Event_Type eventType);
	void remove_handler(IEventHandler<SOCKET> *eventHandler,Event_Type eventType);
	void remove_handler(Handler<SOCKET> handler, Event_Type eventType);

	bool handle_events(timeval *timeout = 0);

private:
	QueueManager<QueueElement>* myQueue;
	DemuxTable demuxTable;
	int nextHandler();
	int freeHandleConnections;
	SyncEventDemultiplexer synch;
};

